package com.example.mq.mqServer.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * @BelongsProject: 0.mq
 * @BelongsPackage: com.example.mq.util
 * @Author : 游在海里的鱼
 * @CreateTime : 2023-12-03  16:58
 * @Version : 1.0
 * @Description : TODO
 */
public class JsonUtils {

    private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

    //从json转成T类型
    public static <T>T setSrc(String json, TypeReference<T> typeReference) throws JsonProcessingException {
        return OBJECT_MAPPER.readValue(json,typeReference);
    }

    //从T类型转成json
    public static String getJson(Object src) throws JsonProcessingException {
        return OBJECT_MAPPER.writeValueAsString(src);
    }
}
